import java.util.HashMap;
import java.util.Map;


public class Cookies {
	private Map<String, String> cookies;
	public Cookies(){
		cookies = new HashMap<String, String>();
	}
	public void addCookies(String cookies){
		String[] cs = cookies.split(";");
		for(int i = 0; i < cs.length; i++){
			String[] ck = cs[i].split("=");
			System.out.println(cs[i]);
			if(ck.length == 2){
				this.cookies.put(ck[0].trim(), ck[1].trim());
			}
		}
	}
	
	public void addCookies(Map<String, String> headers){
		String cookies = headers.get("Set-Cookie");
		if(cookies != null && !cookies.trim().equals("")){
			addCookies(cookies);
		}
	}
	
	public Map<String, String> getCookies(){
		return cookies;
	}
	
	public String getStrCookies(){
		StringBuffer sb = new StringBuffer();
		for(Map.Entry<String, String> entry : cookies.entrySet()){
			sb.append(entry.getKey());
			sb.append("=");
			sb.append(entry.getValue());
			sb.append("; ");
		}
		if(cookies.size() != 0){
			sb.delete(sb.length() - 2, sb.length());
		}
		return sb.toString();
	}
}
